﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuildPlannerLib.Buildings;
using BuildPlannerLib.Enums;
using BuildPlannerLib.PlayerActions;
using BuildPlannerLib.SimEvents;

namespace BuildPlannerLib.Terran.PlayerActions
{
    // Derived class from Action for salvaging a Bunker
    public class SalvageBunker : PlayerAction
    {
        // Constructor with a parameter for build
        public SalvageBunker(Build build)
        {
            Build = build;
            TimeDuration = 500;
            Description = "Use Salvage Bunker";
            LongDescription = "Using the Salvage Bunker ability on an existing Bunker.";
        }

        // Evaluates whether the player is Terran and whether there will be a Bunker to salvage
        public override bool RequirementsFilled()
        {
            NonProduction building = Build.Player.GetBuilding("Bunker") as NonProduction;
            Error = null;

            if (building == null)
            {
                Error = "This action can only be performed by Terran players.";
                return false;
            }

            if (building.Started == 0)
            {
                Error = "There are no bunkers available to salvage.";
                return false;
            }

            return base.RequirementsFilled();
        }
        
        // Evaluates if there is a finished Bunker to salvage
        public override bool StartCheck()
        {
            NonProduction building = Build.Player.GetBuilding("Bunker") as NonProduction;

            if (building.GetCount() == 0)
                return false;

            return base.StartCheck();
        }

        // Removes the bunker and adds the event to finish the action
        public override void StartAction()
        {
            NonProduction building = Build.Player.GetBuilding("Bunker") as NonProduction;

            base.StartAction();

            building.Count--;
            building.Started--;
        }

        // Adds the minerals from the salvage
        public override void FinishAction()
        {
            base.FinishAction();

            Build.Player.Minerals.Change(75);
        }
    }
}
